home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directplay.chm / code / imgutil.js < prev    next >
Encoding:
Text File  |  2004-09-27  |  3.3 KB  |  139 lines

  1. <![CDATA[
  2.  
  3. /*
  4. Image Resolver code.
  5.  
  6. Typical XSL markup usage looks like the following:
  7.  
  8. <xsl:choose>
  9.   <xsl:when expr="goImage.Lookup('img_ieget_animated', goCtx)">
  10.   <IMG BORDER="0">
  11.   <xsl:attribute name="SRC"><xsl:eval>goImage.GetHREF()</xsl:eval></xsl:attribute>
  12.   <xsl:attribute name="ALT"><xsl:eval>goImage.GetName()</xsl:eval></xsl:attribute>
  13.   <xsl:attribute name="HEIGHT"><xsl:eval>goImage.GetHeight()</xsl:eval></xsl:attribute>
  14.   <xsl:attribute name="WIDTH"><xsl:eval>goImage.GetWidth()</xsl:eval></xsl:attribute>
  15.   </IMG>
  16.   </xsl:when>
  17.   <xsl:otherwise><SPAN CLASS="clsBadImg"><xsl:eval>goImage.GetError()</xsl:eval></SPAN></xsl:otherwise>
  18. </xsl:choose>
  19.  
  20. */
  21.  
  22. function CImage(oCtx)
  23. {
  24.   this._oCtx = oCtx;
  25.   this._lastRID = null;
  26.   this._lastImg = null;
  27. }
  28.  
  29. CImage.prototype.Init = function()
  30. {
  31.   var vPropName;
  32.   for (vPropName in this)
  33.   {
  34.     if (typeof(this[vPropName]) != 'function')
  35.     {
  36.       delete(this[vPropName]);
  37.     }
  38.   }
  39. }
  40.  
  41. CImage.prototype.Lookup = function(sRID, oCtx)
  42. {
  43.   if (!sRID)
  44.   {
  45.     this._error = "must specify rid to lookup image";
  46.     return false;
  47.   }
  48.  
  49.   // did we just look it up?
  50.   if (sRID == this._lastRID)
  51.   {
  52.     return true;
  53.   }
  54.  
  55.   // cache images
  56.   if (typeof(this._table) == 'undefined')
  57.   {
  58.     this._table = new Array();
  59.   }
  60.  
  61.   // see if the image has already been looked up
  62.   this._lastImg = this._table[sRID];
  63.   if (!this._lastImg)
  64.   {
  65.     var oImgNode = ownerDocument.selectSingleNode("/inetsdk:topic/inetsdk:images/image[@id='" + sRID + "']");
  66.     if (!oImgNode)
  67.     {
  68.       this._error = "image not found (" + sRID + ")";
  69.       return false;
  70.     }
  71.  
  72.     this._lastImg = this._table[sRID] = new Object();
  73.  
  74.     this._lastImg.name = oImgNode.getAttribute("name");
  75.     this._lastImg.height = oImgNode.getAttribute("height");
  76.     this._lastImg.width = oImgNode.getAttribute("width");
  77.  
  78.     var sHREF = oImgNode.getAttribute("href");
  79.  
  80. //at:     if (oCtx && (oCtx._media == 'chm' || oCtx._media == 'hxs'))
  81.     if (oCtx && (oCtx._media == 'chm'))
  82.     {
  83.       if (!goTD.Ensure())
  84.       {
  85.         this._error = goTD.GetError();
  86.         return false;
  87.       }
  88.  
  89.       this._lastImg.href = MakeRelative(goTD.GetHREF(), sHREF);
  90.       if (!this._lastImg.href)
  91.       {
  92.         this._error = "VROOT2Relative failure.";
  93.         return false;
  94.       }
  95.     }
  96.     else
  97.     {
  98.       this._lastImg.href = sHREF;
  99.     }
  100.  
  101.   }
  102.  
  103.   this._lastRID = sRID;
  104.  
  105.   return true;
  106. }
  107.  
  108. // return the name of the image for its ALT text
  109. CImage.prototype.GetName = function()
  110. {
  111.   return (typeof(this._lastImg.name) != 'undefined' ? this._lastImg.name : '');
  112. }
  113.  
  114. // return the SRC for the image
  115. CImage.prototype.GetHREF = function()
  116. {
  117.   return (typeof(this._lastImg.href) != 'undefined' ? this._lastImg.href : '');
  118. }
  119.  
  120. // return the optimum width of the image
  121. CImage.prototype.GetWidth = function()
  122. {
  123.   return (typeof(this._lastImg.width) != 'undefined' ? this._lastImg.width : '');
  124. }
  125.  
  126. // return the optimum height of the image
  127. CImage.prototype.GetHeight = function()
  128. {
  129.   return (typeof(this._lastImg.height) != 'undefined' ? this._lastImg.height : '');
  130. }
  131.  
  132. // return the last error that occurred during image lookup
  133. CImage.prototype.GetError = function()
  134. {
  135.   return (typeof(this._error) != 'undefined' ? this._error : '');
  136. }
  137.  
  138. ]]>
  139.